package mm.chenchen.modules.host.service.impl;
import mm.chenchen.constant.ResultMsg;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import mm.chenchen.utils.R;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import mm.chenchen.modules.host.entity.HostSoftware;
import mm.chenchen.modules.host.dao.HostSoftwareDao;
import mm.chenchen.modules.host.service.HostSoftwareService;
import mm.chenchen.utils.PageUtils;
import mm.chenchen.utils.PageModel;

import java.util.Map;
import mm.chenchen.modules.host.dao.model.request.HostSoftwareQuery;
import org.springframework.util.ObjectUtils;


@Service("hostSoftwareService")
public class HostSoftwareServiceImpl extends ServiceImpl<HostSoftwareDao, HostSoftware> implements HostSoftwareService {


    public R findPage(Page<Map> page, HostSoftwareQuery param) {
        IPage<HostSoftware> pageData = baseMapper.findPage(page, param);
        if (pageData != null) {
            return R.ok().setData(new PageModel(pageData.getRecords(),pageData.getTotal(),pageData.getSize(),pageData.getCurrent()));
        } else {
            return R.error(ResultMsg.DATA_NOT_EXIT);
        }
    }

    public R getById(Long id){
        return R.ok().setData(super.getById(id));
    };

    public R saveInfo(HostSoftware param){
        return R.ok().setData(super.save(param));
    };

    public R update(HostSoftware param){
            HostSoftware data=super.getById(param.getId());
            if(ObjectUtils.isEmpty(data)){
                return R.error(ResultMsg.DATA_NOT_EXIT);
            }
        return R.ok().setData(super.updateById(param));
    };

    public R deleteById(Long id){
        return R.ok().setData(super.removeById(id));
    };

}